/**
 * This file is released under the GNU General Public License.
 * Refer to the COPYING file distributed with this package.
 *
 * Copyright (c) 2008-2009 WURFL-Pro srl
 */
package net.sourceforge.wurfl.core.handlers.matchers;

import java.util.SortedSet;

import net.sourceforge.wurfl.core.handlers.Handler;
import net.sourceforge.wurfl.core.utils.StringUtils;

/**
 * @author WURFL-PRO SRL, Rome, Italy
 * @version $Id: LGMatcher.java 1045 2009-03-09 15:52:53Z filippo.deluca $
 */
public class LGMatcher extends AbstractMatcher {

	public LGMatcher(Handler handler) {
		super(handler);
	}

	/**
	 * If UA starts with either "LG/" or "LGE/" apply RIS(SS) otherwise apply the default.
	 */
	protected String lookForMatchingUserAgent(SortedSet userAgentsSet, String userAgent) {
		if (userAgent.startsWith("LGE/") || userAgent.startsWith("LG/")) {
			int tollerance = StringUtils.secondSlash(userAgent);

			if (logger.isDebugEnabled()) {
				logger.debug("Applying RIS(SS) UA: " + userAgent);
			}

			return StringUtils.risMatch(userAgentsSet, userAgent, tollerance);
		}

		return super.lookForMatchingUserAgent(userAgentsSet, userAgent);

	}

}
